﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Xml;
using System.Collections.Generic;

namespace DBtuning
{
    /// <summary>
    /// Summary description for Filereader
    /// </summary>
    public class Filereader
    {
        public const string ElementPerfConfigName = "PerfConfig";
        public const string AttribParamID = "ID";
        public const string AttribParamName = "ThresholdName";
        public const string AttribParamThreshold = "Threshold";
        public const string AttribParamWarning = "WarningValue";
        public const string AttribParamDescription = "Description";
        public const string AttribParamUnit = "Unit";
        public const string AttribParamDefault = "Default";

        public Filereader()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        static XmlDocument getParamXmlDoc()
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(HttpContext.Current.Server.MapPath("~/App_Data/PerfConfig.xml"));
            return doc;
        }

        public static System.Collections.Generic.IDictionary<string, string> GetPerformanceParamNames()
        {
            return GetPerformanceParamAttrib(AttribParamName);
        }
        public static System.Collections.Generic.IDictionary<string, string> GetPerformanceParamDescriptions()
        {
            return GetPerformanceParamAttrib(AttribParamDescription);
        }
        public static System.Collections.Generic.IDictionary<string, string> GetPerformanceParamThresholds()
        {
            return GetPerformanceParamAttrib(AttribParamThreshold);
        }
        public static System.Collections.Generic.IDictionary<string, string> GetPerformanceParamWarnings()
        {
            return GetPerformanceParamAttrib(AttribParamWarning);
        }
        public static System.Collections.Generic.IDictionary<string, string> GetPerformanceParamUnits()
        {
            return GetPerformanceParamAttrib(AttribParamUnit);
        }

        private static System.Collections.Generic.IDictionary<string, string> GetPerformanceParamAttrib(string attribName)
        {
            try
            {
                Dictionary<string, string> dict = new Dictionary<string, string>();
                XmlDocument doc = getParamXmlDoc();
                XmlNodeList list = doc.GetElementsByTagName(ElementPerfConfigName);
                foreach (XmlElement ele in list)
                {
                    dict.Add(ele.Attributes[AttribParamID].Value, ele.Attributes[attribName].Value);
                }
                return dict;
            }
            catch { }
            return null;
        }
    }
}
